package com.barunsw.bwf.ems.sample;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.barunsw.bwf.ems.common.controller.CommonController;
import com.barunsw.bwf.ems.dto.SampleVo;

/**
 * 샘플 컨트롤러
 */
@Controller
@RequestMapping(value = "/sample")
public class SampleController extends CommonController{
	
	private static final Logger logger = LoggerFactory.getLogger(SampleController.class);
	
	@Autowired
	SampleService sampleService;

	
	/**
	 * 목록 화면
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/view", method = RequestMethod.GET)
	public String viewList() throws Exception {
		return "sample/view";
	}

	
	/**
	 * 목록 조회
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "", method = RequestMethod.GET)
	public @ResponseBody List<SampleVo> listSample() throws Exception {
		return sampleService.getSampleList();
	}
	
	
	/**
	 * 한건 조회
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/{seq}", method = RequestMethod.GET)
	public @ResponseBody SampleVo getSample(@RequestBody @PathVariable long seq) throws Exception {
		return sampleService.getSample(seq);
	}
	
	
	/**
	 * 등록
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "", method = RequestMethod.POST)
	public @ResponseBody String regSample(@RequestBody SampleVo sampleVo) throws Exception {
		sampleService.insertSample(sampleVo);
		return "{\"result\":\"success\"}";
	}
	
	
	/**
	 * 삭제
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/{seq}", method = RequestMethod.DELETE)
	public @ResponseBody String deleteSample(@RequestBody @PathVariable long seq) throws Exception {
		sampleService.deleteSample(seq);
		return "{\"result\":\"success\"}";
	}
}
